package com.gyms.view.wheel;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.gyms.R;
import com.gyms.bean.ThreeWheelBean;

/**
 * 日期选择对话框
 *
 * @author ywl
 */
public abstract class WheelDialog extends Dialog implements View.OnClickListener {

    protected Context context;

    private TextView btnSure;
    private TextView btnCancel;

    private int animationStyle;
    private boolean isTop = false;
    private OnClickSubmitListener onClickSubmitListener = null;

    protected String[] dialogValues = null;
    protected ThreeWheelBean threeWheelBean = new ThreeWheelBean();


    public WheelDialog(Context context, int animationStyle) {
        super(context, R.style.BottomViewTheme_Defalut);
        this.context = context;
        this.animationStyle = animationStyle;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutResId());
        init();
    }

    protected abstract int getLayoutResId();

    private void init() {

        btnSure = (TextView) findViewById(R.id.select_submit);
        btnCancel = (TextView) findViewById(R.id.select_cancel);

        btnSure.setOnClickListener(this);
        btnCancel.setOnClickListener(this);

        this.setCanceledOnTouchOutside(true);
        Window wm = this.getWindow();
        WindowManager m = wm.getWindowManager();
        Display d = m.getDefaultDisplay();
        WindowManager.LayoutParams p = wm.getAttributes();
        p.width = d.getWidth() * 1;
        if (this.isTop) {
            p.gravity = 48;
        } else {
            p.gravity = 80;
        }
        if (this.animationStyle != 0) {
            this.getWindow().setWindowAnimations(this.animationStyle);
        }
    }

    protected void timeStr2Integer() {


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.select_submit:
                if (onClickSubmitListener != null) {
                    timeStr2Integer();
                    onClickSubmitListener.onClickSubmit(dialogValues, threeWheelBean);
                }
                dismiss();
                break;
            case R.id.select_cancel:
                dismiss();
                break;
        }
    }

    public void setOnClickSubmitListener(OnClickSubmitListener onClickSubmitListener) {
        this.onClickSubmitListener = onClickSubmitListener;
    }

    public interface OnClickSubmitListener {

        void onClickSubmit(String[] values, ThreeWheelBean threeWheelBean);
        void onNotTimeSelect();


    }


}